﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Granite.DataAnnotations;

namespace Granite.Commons.Tests.DataAnnotations
{



	[TestClass]
	public class CalculatedFieldAttributeTests
	{
		[TestMethod]
		public void CalculatedFieldAttribute_Test1()
		{
			string fields = "AAA, BBB,CCC";
            var result = new CalculatedFieldAttribute(fields);
			Assert.AreEqual(fields, result.Sources);
			Assert.AreEqual("AAA", result.SourceProperties[0]);
			Assert.AreEqual("BBB", result.SourceProperties[1]);
			Assert.AreEqual("CCC", result.SourceProperties[2]);
		}

		[TestMethod]
		public void CalculatedFieldAttribute_Test2()
		{
			try
			{
				var result = new CalculatedFieldAttribute(null);

				Assert.Fail("Expected an ArgumentNullException");
			}
			catch (ArgumentNullException ex)
			{
				Assert.AreEqual("sources", ex.ParamName, "Incorrect parameter name");
			}
		}

		[TestMethod]
		public void CalculatedFieldAttribute_Test3()
		{
			try
			{
				var result = new CalculatedFieldAttribute("");

				Assert.Fail("Expected an ArgumentNullException");
			}
			catch (ArgumentException ex)
			{
				Assert.AreEqual("sources", ex.ParamName, "Incorrect parameter name");
			}
		}


	}
}
